<template>
  <div class="utilization-analysis">
    <el-row>
      <el-col :span="24">
        <dynForm
          :info-form="infoForm"
          :search-tags="searchTags"
          :select-list="selectList"
        >
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="doSearch"
          >
            {{ $t('search') }}</el-button>
        </dynForm>
      </el-col>
    </el-row>
    <el-card class="charts-card">
      <axisChart :bar-data="barData" />
    </el-card>
  </div>
</template>
<script>
import mySetting from '@/mixins/mySetting'
import axisChart from './components/axisChart.vue'
import { getList } from '@/api/OEE/utilizationAnalysis'
import { getYearMonth } from '@/utils/pickTime'
import { getEquipmentTypesList } from '@/api/production/layoutDesign'
import { getEqpModelList } from '@/api/equipment/eqpbase'
export default {
  name: 'EqpStatusManage',
  components: { axisChart },
  mixins: [mySetting],
  data() {
    const searchTags = [
      // { label: this.$t('eqpType'), prop: 'eqpType', tag: 'DynSelect' },
      // { label: this.$t('eqpModel'), prop: 'eqpModel', tag: 'DynSelect' },
      { label: this.$t('eqpName'), prop: 'eqpName', tag: 'DynInput' },
      { label: this.$t('timeInterval'), prop: '', tag: 'Dyndaterange', render: () => {
        return (
          <el-date-picker
            vModel={this.timer}
            type='daterange'
            placeholder={'请选择' + `${this.$t('timeInterval')}`}
            start-placeholder={this.$t('StartDate')}
            end-placeholder={this.$t('EndDate')}
            value-format={'yyyy-MM-dd'}
            format={'yyyy-MM-dd'}>
          </el-date-picker>
        )
      }, valueFormat: 'yyyy-MM-dd' },
      { label: 'X轴', prop: 'x', tag: 'DynSelect' }
    ]
    return {
      infoForm: {
        x: 1
      },
      timer: getYearMonth(0),
      selectList: {
        x: [
          { id: 1, name: '设备名称' },
          { id: 2, name: '时间' }
        ]
      },
      barData: {},
      searchTags: Object.freeze(searchTags)
    }
  },
  created() {
    this.initList()
    this.getEquipmentTypes()
    this.getEqpTypesList()
  },
  methods: {
    async initList() {
      const [startTime, endTime] = this.timer || []
      const res = await getList(this.$clearNull({ ...this.infoForm, startTime, endTime }))
      this.barData = res.data
    },
    doSearch() {
      this.listQuery.page = 1
      this.initList()
    },
    // 获取设备类型列表
    async getEquipmentTypes() {
      const res = await getEquipmentTypesList()
      this.$set(this.selectList, 'eqpType', res.data)
    },
    async getEqpTypesList() {
      const res = await getEqpModelList()
      this.$set(this.selectList, 'eqpModel', res.data)
    }
  }
}
</script>
<style lang="scss" scoped>
@import "~@/assets/styles/defaultStyle.scss";
::v-deep .el-row:nth-child(1) {
  padding-bottom: 0;
}
::v-deep .el-form {
  padding-top: 10px;
  // .el-form-item {
  //   margin-bottom: 15px;
  // }
}
.utilization-analysis{
  padding-bottom: 40px;
}
</style>
